const http = require('http')
const url = require('url')
const path = require('path')
const fileRequst = require('./services/web/fileRequest')
const apiRequst = require('./services/apiRequest')

const serverConfig = {
    staticPath:'dist',
    adminStaticPath:'admin',
    apiPath:'req'
}



const server = http.createServer((req,res)=>{
    let _path = url.parse(req.url).pathname
    let apiPathReg = new RegExp(`^\/${serverConfig.apiPath}`)
    let adminStaticPathReg = new RegExp(`^\/${serverConfig.adminStaticPath}`)
    if(apiPathReg.test(_path)){
        console.log('这是要请求接口')
        apiRequst(_path, req, res)
    } else {
        _path = path.join(__dirname, adminStaticPathReg.test(_path)?'':'dist/', _path)
        fileRequst(_path, req, res)
    }
})


